<?php
/**
 * Created by PhpStorm.
 * User: xiangkevin
 * Date: 28/09/2017
 * Time: 7:58 PM
 */
namespace App\Http\Validators;

use Illuminate\Http\Request;
use Validator;

class MusicValidator
{
    public static function create(Request $request)
    {
        $only = ['beat_id','mixture_url','lyric_content','music_title','music_author'];

        $rules = [
            'beat_id' => 'required',
            'mixture_url' => 'required',
//            'lyric_content' => 'required',
            'music_title' => 'required',
            'music_author' => 'required'
        ];

        $messages = [
            'beat_id.required' => '伴奏不能为空。',
            'mixture_url.required' => '音乐地址不能为空。',
            'music_title.required' => '音乐标题不能为空。',
            'music_author.required' => '音乐作者不能为空。',
        ];

        $input = $request->only($only);

        $validator = Validator::make($input, $rules, $messages);

        if ($validator->fails())
            exit(json_encode(['info'=>$validator->errors()->first(), 'code' => 1001,'data'=>""]));

        return $input;

    }
}
